package com.example.vspm.mapper;


import com.example.vspm.entity.TaskForm;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author LCL
 * @date 2022/1/6
 * @desc
 */
@Repository
@Mapper
public interface TaskFormMapper {
   //增加工单////////////////////////
    @Insert("insert into vspm_taskForm (customerName,customerRole,activityTheme,activityProfile,meetingNumber,connection) values" +
            "(#{customerName},#{customerRole},#{activityTheme},#{activityProfile},#{meetingNumber},#{connection})")
    @Options(useGeneratedKeys=true, keyProperty="tid", keyColumn="tid")
    void addTaskForm(TaskForm taskForm);

    //添加工单报单员的pid1
    @Update("update  vspm_taskForm set pid1=#{pid1} where tid=#{tid}" )
    void addTaskFormPID1(@Param("pid1") int pid1, @Param("tid") int tid);

    //根据session获取的工单id更新数据库中的state
    @Update("update  vspm_taskForm set state=#{state} where tid=#{tid}" )
    void updateState(@Param("state") String state, @Param("tid") int tid);


    //查看工单总工单//////////////////////////////////////////
    //报单员根据session中的person id 查看工单
    @Select("select * from vspm_taskForm where pid1=#{pid1}")
    List<TaskForm> listTaskFormByPid1(int pid1);

    //接单员根据session中的person id 查看工单
    @Select("select * from vspm_taskForm where pid3=#{pid3}")
    List<TaskForm> listTaskFormByPid3(int pid3);

    //派单员查看所有工单
    @Select("select * from vspm_taskForm")
    List<TaskForm> listTaskForm();

    ///////////////////挑选接单员
    //在挑选接单员的时候,根据前端传来的pid3录入到工单表中
    @Update("update  vspm_taskForm set pid3=#{pid3} where tid=#{taid}" )
    void addTaskFormPID3(@Param("pid3") int pid3, @Param("taid") int tid);

    //接单员拒绝,根据前端传过来的工单id将pid3设置成0
    @Update("update  vspm_taskForm set pid3=#{pid3} where tid=#{taid}" )
    void updateTaskFormPID3(@Param("pid3") int pid3, @Param("taid") int tid);


//    //查看工单和会场
//    @Select("select * from vspm_taskForm t1 left join vspm_meetingPlace t2 on t1.tid=t2.taid")
//    List<TaskForm> listTaskForm();



    //查看工单详情页,根据前端传过来的工单tid查看,方便显示会场
    @Select("select * from vspm_taskForm where tid=#{tid}")
    List<TaskForm> listTaskFormByTID(int tid);





//    //查看工单详情,根据前端传回的id
//    @Select("select * from vspm_taskForm where tid=#{tid}")
//    List<TaskForm> listTaskFormById(int tid);

   //根据tid删除工单
   @Delete("delete from vspm_taskForm where tid=#{tid}")
   void deleteTaskForm(int tid);


    //根据工单tid更新
    @Update("")
    TaskForm updateTaskForm(TaskForm taskForm);




}
